.class public Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;
.super Landroid/os/AsyncTask;
.source "AsyncRequest.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/sponsorpay/sdk/android/publisher/AsyncRequest$AsyncRequestResultListener;
    }
.end annotation

.annotation system Ldalvik/annotation/Signature;
    value = {
        "Landroid/os/AsyncTask",
        "<",
        "Ljava/lang/Void;",
        "Ljava/lang/Void;",
        "Ljava/lang/Void;",
        ">;"
    }
.end annotation


# static fields
.field private static ACCEPT_LANGUAGE_HEADER_NAME:Ljava/lang/String; = null

.field public static LOG_TAG:Ljava/lang/String; = null

.field private static final SIGNATURE_HEADER:Ljava/lang/String; = "X-Sponsorpay-Response-Signature"

.field private static USER_AGENT_HEADER_NAME:Ljava/lang/String;

.field private static USER_AGENT_HEADER_VALUE:Ljava/lang/String;

.field public static shouldLogVerbosely:Z


# instance fields
.field private mCookieStrings:[Ljava/lang/String;

.field private mRequestUrl:Ljava/lang/String;

.field private mResponseBody:Ljava/lang/String;

.field private mResponseSignature:Ljava/lang/String;

.field private mResultListener:Lcom/sponsorpay/sdk/android/publisher/AsyncRequest$AsyncRequestResultListener;

.field private mStatusCode:I

.field private mThrownRequestError:Ljava/lang/Throwable;


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .prologue
    .line 36
    const/4 v0, 0x0

    sput-boolean v0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->shouldLogVerbosely:Z

    .line 38
    const-string v0, "AsyncRequest"

    sput-object v0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->LOG_TAG:Ljava/lang/String;

    .line 43
    const-string v0, "User-Agent"

    sput-object v0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->USER_AGENT_HEADER_NAME:Ljava/lang/String;

    .line 48
    const-string v0, "Accept-Language"

    sput-object v0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->ACCEPT_LANGUAGE_HEADER_NAME:Ljava/lang/String;

    .line 53
    const-string v0, "Android"

    sput-object v0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->USER_AGENT_HEADER_VALUE:Ljava/lang/String;

    .line 58
    return-void
.end method

.method public constructor <init>(Ljava/lang/String;Lcom/sponsorpay/sdk/android/publisher/AsyncRequest$AsyncRequestResultListener;)V
    .locals 0
    .parameter "requestUrl"
    .parameter "listener"

    .prologue
    .line 105
    invoke-direct {p0}, Landroid/os/AsyncTask;-><init>()V

    .line 106
    iput-object p1, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mRequestUrl:Ljava/lang/String;

    .line 107
    iput-object p2, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mResultListener:Lcom/sponsorpay/sdk/android/publisher/AsyncRequest$AsyncRequestResultListener;

    .line 108
    return-void
.end method

.method private makeAcceptLanguageHeaderValue()Ljava/lang/String;
    .locals 7

    .prologue
    .line 173
    invoke-static {}, Ljava/util/Locale;->getDefault()Ljava/util/Locale;

    move-result-object v3

    invoke-virtual {v3}, Ljava/util/Locale;->getLanguage()Ljava/lang/String;

    move-result-object v2

    .line 175
    .local v2, preferredLanguage:Ljava/lang/String;
    move-object v0, v2

    .line 176
    .local v0, acceptLanguageLocaleValue:Ljava/lang/String;
    sget-object v3, Ljava/util/Locale;->ENGLISH:Ljava/util/Locale;

    invoke-virtual {v3}, Ljava/util/Locale;->getLanguage()Ljava/lang/String;

    move-result-object v1

    .line 178
    .local v1, englishLanguageCode:Ljava/lang/String;
    invoke-static {v2}, Lcom/sponsorpay/sdk/android/utils/StringUtils;->nullOrEmpty(Ljava/lang/String;)Z

    move-result v3

    if-eqz v3, :cond_1

    .line 179
    move-object v0, v1

    .line 183
    :cond_0
    :goto_0
    return-object v0

    .line 180
    :cond_1
    invoke-virtual {v1, v2}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v3

    if-nez v3, :cond_0

    .line 181
    new-instance v3, Ljava/lang/StringBuilder;

    invoke-static {v0}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v4

    invoke-direct {v3, v4}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v4, ", %s;q=0.8"

    const/4 v5, 0x1

    new-array v5, v5, [Ljava/lang/Object;

    const/4 v6, 0x0

    aput-object v1, v5, v6

    invoke-static {v4, v5}, Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v4

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    goto :goto_0
.end method


# virtual methods
.method public didRequestThrowError()Z
    .locals 1

    .prologue
    .line 246
    iget-object v0, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mThrownRequestError:Ljava/lang/Throwable;

    if-eqz v0, :cond_0

    const/4 v0, 0x1

    :goto_0
    return v0

    :cond_0
    const/4 v0, 0x0

    goto :goto_0
.end method

.method protected bridge varargs synthetic doInBackground([Ljava/lang/Object;)Ljava/lang/Object;
    .locals 1
    .parameter

    .prologue
    .line 1
    check-cast p1, [Ljava/lang/Void;

    invoke-virtual {p0, p1}, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->doInBackground([Ljava/lang/Void;)Ljava/lang/Void;

    move-result-object v0

    return-object v0
.end method

.method protected varargs doInBackground([Ljava/lang/Void;)Ljava/lang/Void;
    .locals 14
    .parameter "params"

    .prologue
    const/4 v13, 0x0

    .line 119
    new-instance v4, Lorg/apache/http/client/methods/HttpGet;

    iget-object v8, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mRequestUrl:Ljava/lang/String;

    invoke-direct {v4, v8}, Lorg/apache/http/client/methods/HttpGet;-><init>(Ljava/lang/String;)V

    .line 120
    .local v4, request:Lorg/apache/http/client/methods/HttpUriRequest;
    sget-object v8, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->USER_AGENT_HEADER_NAME:Ljava/lang/String;

    sget-object v9, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->USER_AGENT_HEADER_VALUE:Ljava/lang/String;

    invoke-interface {v4, v8, v9}, Lorg/apache/http/client/methods/HttpUriRequest;->addHeader(Ljava/lang/String;Ljava/lang/String;)V

    .line 122
    invoke-direct {p0}, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->makeAcceptLanguageHeaderValue()Ljava/lang/String;

    move-result-object v0

    .line 123
    .local v0, acceptLanguageHeaderValue:Ljava/lang/String;
    sget-boolean v8, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->shouldLogVerbosely:Z

    if-eqz v8, :cond_0

    .line 124
    invoke-virtual {p0}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v8

    invoke-virtual {v8}, Ljava/lang/Class;->getSimpleName()Ljava/lang/String;

    move-result-object v8

    new-instance v9, Ljava/lang/StringBuilder;

    const-string v10, "acceptLanguageHeaderValue: "

    invoke-direct {v9, v10}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    .line 125
    invoke-virtual {v9, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v9

    invoke-virtual {v9}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v9

    .line 124
    invoke-static {v8, v9}, Lcom/sponsorpay/sdk/android/utils/SponsorPayLogger;->i(Ljava/lang/String;Ljava/lang/String;)V

    .line 128
    :cond_0
    sget-object v8, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->ACCEPT_LANGUAGE_HEADER_NAME:Ljava/lang/String;

    invoke-interface {v4, v8, v0}, Lorg/apache/http/client/methods/HttpUriRequest;->addHeader(Ljava/lang/String;Ljava/lang/String;)V

    .line 130
    invoke-static {}, Lcom/sponsorpay/sdk/android/utils/SPHttpClient;->getHttpClient()Lorg/apache/http/client/HttpClient;

    move-result-object v1

    .line 132
    .local v1, client:Lorg/apache/http/client/HttpClient;
    iput-object v13, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mThrownRequestError:Ljava/lang/Throwable;

    .line 136
    :try_start_0
    invoke-interface {v1, v4}, Lorg/apache/http/client/HttpClient;->execute(Lorg/apache/http/client/methods/HttpUriRequest;)Lorg/apache/http/HttpResponse;

    move-result-object v5

    .line 137
    .local v5, response:Lorg/apache/http/HttpResponse;
    invoke-interface {v5}, Lorg/apache/http/HttpResponse;->getStatusLine()Lorg/apache/http/StatusLine;

    move-result-object v8

    invoke-interface {v8}, Lorg/apache/http/StatusLine;->getStatusCode()I

    move-result v8

    iput v8, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mStatusCode:I

    .line 138
    invoke-static {v5}, Lcom/sponsorpay/sdk/android/utils/HttpResponseParser;->extractResponseString(Lorg/apache/http/HttpResponse;)Ljava/lang/String;

    move-result-object v8

    iput-object v8, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mResponseBody:Ljava/lang/String;

    .line 139
    const-string v8, "X-Sponsorpay-Response-Signature"

    invoke-interface {v5, v8}, Lorg/apache/http/HttpResponse;->getHeaders(Ljava/lang/String;)[Lorg/apache/http/Header;

    move-result-object v6

    .line 140
    .local v6, responseSignatureHeaders:[Lorg/apache/http/Header;
    array-length v8, v6

    if-lez v8, :cond_3

    const/4 v8, 0x0

    aget-object v8, v6, v8

    .line 141
    invoke-interface {v8}, Lorg/apache/http/Header;->getValue()Ljava/lang/String;

    move-result-object v8

    .line 140
    :goto_0
    iput-object v8, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mResponseSignature:Ljava/lang/String;

    .line 142
    const-string v8, "Set-Cookie"

    invoke-interface {v5, v8}, Lorg/apache/http/HttpResponse;->getHeaders(Ljava/lang/String;)[Lorg/apache/http/Header;

    move-result-object v2

    .line 145
    .local v2, cookieHeaders:[Lorg/apache/http/Header;
    array-length v8, v2

    if-lez v8, :cond_2

    .line 147
    sget-boolean v8, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->shouldLogVerbosely:Z

    if-eqz v8, :cond_1

    .line 148
    sget-object v8, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->LOG_TAG:Ljava/lang/String;

    const-string v9, "Got following cookies from server (url: %s):"

    const/4 v10, 0x1

    new-array v10, v10, [Ljava/lang/Object;

    const/4 v11, 0x0

    .line 149
    iget-object v12, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mRequestUrl:Ljava/lang/String;

    aput-object v12, v10, v11

    .line 148
    invoke-static {v9, v10}, Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v9

    invoke-static {v8, v9}, Lcom/sponsorpay/sdk/android/utils/SponsorPayLogger;->v(Ljava/lang/String;Ljava/lang/String;)V

    .line 152
    :cond_1
    array-length v8, v2

    new-array v8, v8, [Ljava/lang/String;

    iput-object v8, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mCookieStrings:[Ljava/lang/String;

    .line 153
    const/4 v3, 0x0

    .local v3, i:I
    :goto_1
    array-length v8, v2

    if-lt v3, v8, :cond_4

    .line 164
    .end local v2           #cookieHeaders:[Lorg/apache/http/Header;
    .end local v3           #i:I
    .end local v5           #response:Lorg/apache/http/HttpResponse;
    .end local v6           #responseSignatureHeaders:[Lorg/apache/http/Header;
    :cond_2
    :goto_2
    return-object v13

    .line 141
    .restart local v5       #response:Lorg/apache/http/HttpResponse;
    .restart local v6       #responseSignatureHeaders:[Lorg/apache/http/Header;
    :cond_3
    const-string v8, ""

    goto :goto_0

    .line 154
    .restart local v2       #cookieHeaders:[Lorg/apache/http/Header;
    .restart local v3       #i:I
    :cond_4
    iget-object v8, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mCookieStrings:[Ljava/lang/String;

    aget-object v9, v2, v3

    invoke-interface {v9}, Lorg/apache/http/Header;->getValue()Ljava/lang/String;

    move-result-object v9

    aput-object v9, v8, v3

    .line 155
    sget-boolean v8, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->shouldLogVerbosely:Z

    if-eqz v8, :cond_5

    .line 156
    sget-object v8, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->LOG_TAG:Ljava/lang/String;

    iget-object v9, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mCookieStrings:[Ljava/lang/String;

    aget-object v9, v9, v3

    invoke-static {v8, v9}, Lcom/sponsorpay/sdk/android/utils/SponsorPayLogger;->v(Ljava/lang/String;Ljava/lang/String;)V
    :try_end_0
    .catch Ljava/lang/Throwable; {:try_start_0 .. :try_end_0} :catch_0

    .line 153
    :cond_5
    add-int/lit8 v3, v3, 0x1

    goto :goto_1

    .line 160
    .end local v2           #cookieHeaders:[Lorg/apache/http/Header;
    .end local v3           #i:I
    .end local v5           #response:Lorg/apache/http/HttpResponse;
    .end local v6           #responseSignatureHeaders:[Lorg/apache/http/Header;
    :catch_0
    move-exception v7

    .line 161
    .local v7, t:Ljava/lang/Throwable;
    sget-object v8, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->LOG_TAG:Ljava/lang/String;

    new-instance v9, Ljava/lang/StringBuilder;

    const-string v10, "Exception triggered when executing request: "

    invoke-direct {v9, v10}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v9, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    move-result-object v9

    invoke-virtual {v9}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v9

    invoke-static {v8, v9}, Lcom/sponsorpay/sdk/android/utils/SponsorPayLogger;->e(Ljava/lang/String;Ljava/lang/String;)V

    .line 162
    iput-object v7, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mThrownRequestError:Ljava/lang/Throwable;

    goto :goto_2
.end method

.method public getCookieStrings()[Ljava/lang/String;
    .locals 1

    .prologue
    .line 202
    iget-object v0, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mCookieStrings:[Ljava/lang/String;

    return-object v0
.end method

.method public getHttpStatusCode()I
    .locals 1

    .prologue
    .line 229
    iget v0, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mStatusCode:I

    return v0
.end method

.method public getRequestThrownError()Ljava/lang/Throwable;
    .locals 1

    .prologue
    .line 255
    iget-object v0, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mThrownRequestError:Ljava/lang/Throwable;

    return-object v0
.end method

.method public getRequestUrl()Ljava/lang/String;
    .locals 1

    .prologue
    .line 237
    iget-object v0, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mRequestUrl:Ljava/lang/String;

    return-object v0
.end method

.method public getResponseBody()Ljava/lang/String;
    .locals 1

    .prologue
    .line 222
    iget-object v0, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mResponseBody:Ljava/lang/String;

    return-object v0
.end method

.method public getResponseSignature()Ljava/lang/String;
    .locals 1

    .prologue
    .line 233
    iget-object v0, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mResponseSignature:Ljava/lang/String;

    return-object v0
.end method

.method public hasCookies()Z
    .locals 4

    .prologue
    const/4 v3, 0x0

    .line 208
    iget-object v2, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mCookieStrings:[Ljava/lang/String;

    if-eqz v2, :cond_0

    iget-object v2, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mCookieStrings:[Ljava/lang/String;

    array-length v2, v2

    if-nez v2, :cond_1

    .line 209
    :cond_0
    invoke-static {v3}, Ljava/lang/Boolean;->valueOf(Z)Ljava/lang/Boolean;

    move-result-object v1

    .line 215
    .local v1, retval:Ljava/lang/Boolean;
    :goto_0
    invoke-virtual {v1}, Ljava/lang/Boolean;->booleanValue()Z

    move-result v2

    return v2

    .line 211
    .end local v1           #retval:Ljava/lang/Boolean;
    :cond_1
    iget-object v2, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mCookieStrings:[Ljava/lang/String;

    aget-object v0, v2, v3

    .line 212
    .local v0, firstCookieString:Ljava/lang/String;
    invoke-static {v0}, Lcom/sponsorpay/sdk/android/utils/StringUtils;->notNullNorEmpty(Ljava/lang/String;)Z

    move-result v2

    invoke-static {v2}, Ljava/lang/Boolean;->valueOf(Z)Ljava/lang/Boolean;

    move-result-object v1

    .restart local v1       #retval:Ljava/lang/Boolean;
    goto :goto_0
.end method

.method public hasSucessfulStatusCode()Z
    .locals 2

    .prologue
    .line 263
    iget v0, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mStatusCode:I

    const/16 v1, 0xc8

    if-lt v0, v1, :cond_0

    iget v0, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mStatusCode:I

    const/16 v1, 0x190

    if-ge v0, v1, :cond_0

    const/4 v0, 0x1

    :goto_0
    return v0

    :cond_0
    const/4 v0, 0x0

    goto :goto_0
.end method

.method protected bridge synthetic onPostExecute(Ljava/lang/Object;)V
    .locals 0
    .parameter

    .prologue
    .line 1
    check-cast p1, Ljava/lang/Void;

    invoke-virtual {p0, p1}, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->onPostExecute(Ljava/lang/Void;)V

    return-void
.end method

.method protected onPostExecute(Ljava/lang/Void;)V
    .locals 1
    .parameter "result"

    .prologue
    .line 194
    invoke-super {p0, p1}, Landroid/os/AsyncTask;->onPostExecute(Ljava/lang/Object;)V

    .line 195
    iget-object v0, p0, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;->mResultListener:Lcom/sponsorpay/sdk/android/publisher/AsyncRequest$AsyncRequestResultListener;

    invoke-interface {v0, p0}, Lcom/sponsorpay/sdk/android/publisher/AsyncRequest$AsyncRequestResultListener;->onAsyncRequestComplete(Lcom/sponsorpay/sdk/android/publisher/AsyncRequest;)V

    .line 196
    return-void
.end method
